from cms.cython_support cimport *

cdef enum:
	MACRO_STACK_SIZE	= 64
	MACRO_STACK_NAME_SIZE	= 32

cdef struct _StackElem:
	int64_t lineno
	Py_UCS4 name[MACRO_STACK_NAME_SIZE]

cdef class _IndexRef(object):
	cdef int64_t charOffset

cdef class _Anchor(object):
	cdef str name
	cdef str text
	cdef int64_t indent
	cdef _Bool noIndex

	cdef str makeUrl(self, CMSStatementResolver resolver)

cdef class _ArgParserRet(object):
	cdef int64_t cons
	cdef list arguments

cdef class _ResolverRet(object):
	cdef int64_t cons
	cdef str data

cdef class CMSStatementResolver(object):
	cdef public object cms
	cdef public dict variables
	cdef public object pageIdent
	cdef public uint64_t charCount
	cdef public list indexRefs
	cdef public list anchors

	cdef _StackElem __callStack[MACRO_STACK_SIZE]
	cdef uint16_t __callStackLen
	cdef list __macroArgs

	cdef dict __handlers
	cdef str __escapedChars
	cdef str VARNAME_CHARS

	cdef str expandVariable(self, str name)

	cpdef str escape(self, str data)
	cpdef str unescape(self, str data)

	cdef _ResolverRet __do_compare(self, str d, int64_t dOffs, _Bool invert)
	cdef str __do_arith(self, object oper, list args)

	cdef _ArgParserRet __parseArguments(self, str d, int64_t dOffs, _Bool strip)
	cdef _ResolverRet __doMacro(self, str macroname, str d, int64_t dOffs)
	cdef _ResolverRet __expandRecStmts(self, str d, int64_t dOffs, str stopchars)
